<template>
  <div>
    <div class="center">
      <!--  -->
      <!-- :name="areaName" :path="pathArea" -->
      <maparea @update="update"></maparea>
    </div>
  </div>
</template>
<style scoped></style>
<script>
import maparea from "./map-area.vue";

export default {
  data() {
    return {
      isCollapse: "",
      location: []
    };
  },
  components: {
    maparea
  },
  activated() {},
  methods: {
    update(arr, center, area, cityCode, cityName) {
      let _this = this;
      let around = [];
      //console.log(arr, center);
      for (let i = 0; i < arr.length; i++) {
        let o = {};
        const element = arr[i];

        element.aroundLocations = element.path;

        let aroundLocations = [];
        for (let j = 0; j < element.path.length; j++) {
          const item = element.path[j];
          let obj = {};
          if (item instanceof Array) {
            obj = {
              lng: item[0],
              lat: item[1]
            };
          } else {
            obj = {
              lng: item.lng,
              lat: item.lat
            };
          }

          aroundLocations.push(obj);
        }
        o.aroundLocations = aroundLocations;

        around.push(o);
      }
      //console.log(around);
      if (around.length > 0) {
        _this
          .$confirm("是否修改?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(() => {
            let data = {};

            this.$http({
              url:
                "hsssystemadmin/v1/businessManagement/insertBusinessInformation",
              method: "POST",
              data: {
                businessArea: area,
                businessAreaCodeDto: arr[0].businessAreaCode,
                businessAreaName: arr[0].name,
                // groupId: _this.groupId,
                centralPointCoordinate: center,
                businessCoordinates: around,
                cityCode: cityCode,
                cityName: cityName
              }
            }).then(res => {
              //console.log(res);
              _this.$message.success("修改成功");
            });
          })
          .catch(() => {
            _this.$message.success("已取消");
          });
      } else {
        this.$message.error("未划分区域");
        return;
      }
    }
  }
};
</script>
